package com.zmzncs.lmtc.module.shop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.lmtc.common.pojo.PageInfo;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.shop.pojo.shop_goods.GoodsAddForm;
import com.zmzncs.lmtc.module.shop.pojo.shop_info.ShopInfoDTO;
import com.zmzncs.lmtc.module.shop.pojo.shop_info.ShopInfoSelectForm;
import com.zmzncs.lmtc.module.shop.pojo.shop_info.ShopInfoTableVO;
import com.zmzncs.lmtc.module.shop.pojo.shop_manager.*;
import com.zmzncs.lmtc.module.shop.service.ShopManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 商户-管理员 前端控制器
 * </p>
 *
 * @author 高博文
 * @since 2021-05-27
 */
@Api(tags = "商户管理员")
@RestController
@RequestMapping("/shop/shop-manager")
public class ShopManagerController {

    @Autowired
    ShopManagerService shopManagerService;

    @ApiOperation(value = "添加商户主")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("add")
    public Rest add(@Valid @RequestBody ShopManagerAddForm form){
        shopManagerService.add(form);
        return RestUtil.success();
    }

    @ApiOperation(value = "根据手机号查询信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType = "query", name = "telephone", value = "手机号", required = true),
    })
    @GetMapping("get-by-telephone")
    public Rest<ShopManagerDTO> getByTelephone(@NotNull String telephone){
        ShopManagerDTO shopManagerDTO = shopManagerService.getByTelephone(telephone);
        return RestUtil.success(shopManagerDTO);
    }

    @ApiOperation(value = "条件分页查询商户管理员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping("get-manager-page")
    public Rest<PageInfo<ShopManagerTableVO>> getManagerPage(@Valid ShopManagerSelectForm form){
        IPage<ShopManagerDTO> managerDTOIPage = shopManagerService.getManagerPage(form);
        PageInfo<ShopManagerTableVO> pageInfo = JsonUtil.pageTransform(managerDTOIPage, ShopManagerTableVO.class);
        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType = "query", name = "managerId", value = "管理员Id", required = true),
    })
    @PostMapping("delete")
    public Rest delete(@NotNull Long managerId){
        shopManagerService.delete(managerId);
        return RestUtil.success();
    }

    @ApiOperation(value = "配置商户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("update-manager")
    public Rest updateManager(@Valid @RequestBody ShopManagerUpdateForm form){
        shopManagerService.updateManager(form);
        return RestUtil.success();
    }



}

